package org.uva.streambuilder;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Observable;
import java.util.Observer;
import javax.swing.border.BevelBorder;


public class ModuleComponent extends JPanel implements Observer{
	
	static int height = 70;
	static int width = 100;
	static int portHeight = 10;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	static Color defaultColor = new Color(69, 147, 243);
        static Color selectedColor = new Color(243, 179, 69);
	
	ArrayList<ModuleComponent> inputList;
	ArrayList<ModuleComponent> outputList;
	Font font;
	double value = 0f;
        
        boolean isSelected = false;
		
	public Dimension getPreferredSize() {
		return new Dimension(width,height);
	}
	
	public ModuleComponent()
	{
		setBorder(new ShadowBorder(Color.black));
            
	
		this.setBackground( defaultColor );
		inputList = new ArrayList<ModuleComponent>();
		outputList = new ArrayList<ModuleComponent>();
		
		font = new Font("Monospace", Font.PLAIN, 10);
                
                
	}
	
	public void setValue(double val)
	{
		value = val;
	}
	
	public double getValue()
	{
		return value;
	}
	
	public Point getInputPostion()
	{
		Point t= this.getLocationOnScreen();
		return new Point(t.x + (t.x + width) / 2, t.y);
	}
	
	public Point getOutputPostion()
	{
		Point t= this.getLocation();
		return new Point(t.x + (t.x + width) / 2, t.y+ height);
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		
                if (isSelected)
                    this.setBackground(selectedColor);
                else
                    this.setBackground( defaultColor );
                
		Graphics2D g2 = (Graphics2D)g;
		g2.setColor(Color.gray);
		g2.fillRect(0, 0, width, portHeight);
		g2.setColor(Color.black);
		g2.drawRect(0, 0, width, portHeight);
		
		g2.setColor(Color.gray);
		g2.fillRect(0, height- portHeight, width, portHeight);
		g2.setColor(Color.black);
		g2.drawRect(0, height- portHeight, width, portHeight);
		
		g2.setFont(font);
		g2.drawString("Module", 10, portHeight + 15);
		g2.drawString(Double.toString(value), 15 , portHeight + 30);

		
	}

	public void update(Observable o, Object arg) {
		// TODO Auto-generated method stub
		
	}
	
	
}
